/**
 * TDS PEC 4
 * Grupo 3H2M
 *
 * El paquete <code>edu.uoc.tds.pec4.mantenimiento</code> agrupa todas las
 * interfaces, clases y elementos de la GUI para la gestión del subsistema 
 * de Mantenimiento
 */
package edu.uoc.tds.pec4.mantenimiento;

import edu.uoc.tds.pec4.beans.AuditoriaDTO;
import edu.uoc.tds.pec4.rmi.GestorMantenimientoInterface;
import edu.uoc.tds.pec4.beans.AulaDTO;
import edu.uoc.tds.pec4.beans.CFisicaDTO;
import edu.uoc.tds.pec4.beans.CiudadDTO;
import edu.uoc.tds.pec4.beans.UsuarioDTO;
import edu.uoc.tds.pec4.common.util.Constantes;
import edu.uoc.tds.pec4.common.util.TDSLanguageUtils;
import edu.uoc.tds.pec4.common.util.UtilidadesGUI;
import edu.uoc.tds.pec4.common.validation.ValidarGUI;
import edu.uoc.tds.pec4.server.bbdd.exceptions.GestorMantenimientoException;
import java.awt.Frame;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.List;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;

/**
 * La clase <code>DialogConsultaAula</code> representa la interfaz de
 * usuario para la actualización de un aula.
 * Permitirá la consulta, baja lógica y modificación de los campos de un 
 * aula, a excepción de su identificador.<br />
 *
 * Interficie de usuario para la actualización de aulas.
 *
 * @author	Luis Rivas Mariño
 * @version	15/12/2011
 * @see		edu.uoc.tds.pec4.rmi.GestorMantenimientoInterface
 */
public class DialogConsultaAula extends javax.swing.JDialog {

    /** objRemoto Es el objeto empleado como interfaz en la comunicación RMI */
    private GestorMantenimientoInterface objRemotoMantenimiento = null;
    /** clientConnected Indica si el cliente está conectado al servidor */
    private boolean clientConnected = false;
    // Identificador del usuario conectado
    private String idConectado;
    /** usLogeado representa al usuario que está autentificado */
    private UsuarioDTO usLogeado;
    private DefaultListModel itemAula;

    /** Creates new form DialogConsultaAula */
    public DialogConsultaAula(java.awt.Frame parent, GestorMantenimientoInterface objRemotoMantenimiento,
            AulaDTO aula, boolean modal, UsuarioDTO usLogeado) throws RemoteException, GestorMantenimientoException {

        super(parent, TDSLanguageUtils.getMessage("mantenimiento.aula.actualizacion.titulo") + " - " + aula.getIdAula(), modal);

        this.usLogeado = usLogeado;

        // Obtenemos el id del usuario 
        idConectado = usLogeado.getIdUsuario();

        conectarCliente();

        initComponents();

        inicializarComponentes();

        //Centramos la ventana en la pantalla
        UtilidadesGUI.centrarVentana(this);

        rellenaDatos(aula);
    }

    /**
     * Conectar con el servidor RMI
     * Permite la conexion con el servidor RMI
     */
    private void conectarCliente() {
        try {
            objRemotoMantenimiento = (GestorMantenimientoInterface) Naming.lookup("GestorMantenimiento");
            clientConnected = true;
        } catch (NotBoundException eNbe) {
            objRemotoMantenimiento = null;
            JOptionPane.showMessageDialog(null,
                    TDSLanguageUtils.getMessage("cliente.error.notbound") + "\n" + eNbe.getMessage(),
                    TDSLanguageUtils.getMessage("cliente.error"), JOptionPane.ERROR_MESSAGE);
        } catch (RemoteException eRe) {
            objRemotoMantenimiento = null;
            JOptionPane.showMessageDialog(null,
                    TDSLanguageUtils.getMessage("cliente.error.url") + "\n" + eRe.getMessage(),
                    TDSLanguageUtils.getMessage("cliente.error"), JOptionPane.ERROR_MESSAGE);
        } catch (MalformedURLException eMULRe) {
            objRemotoMantenimiento = null;
            JOptionPane.showMessageDialog(null,
                    TDSLanguageUtils.getMessage("cliente.error.conn") + "\n" + eMULRe.getMessage(),
                    TDSLanguageUtils.getMessage("cliente.error"), JOptionPane.ERROR_MESSAGE);
        } catch (Exception eE) {
            objRemotoMantenimiento = null;
            JOptionPane.showMessageDialog(null,
                    TDSLanguageUtils.getMessage("cliente.error.conn") + "\n" + eE.getMessage(),
                    TDSLanguageUtils.getMessage("cliente.error"), JOptionPane.ERROR_MESSAGE);
        }
    }

    /** Este método es llamado desde el constructor para 
     *  inicializar el formulario.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelBotones = new javax.swing.JPanel();
        btnModificacion = new javax.swing.JButton();
        btnVolver = new javax.swing.JButton();
        btnBaja = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        lblPrecioHora = new javax.swing.JLabel();
        precioHora = new javax.swing.JTextField();
        lblPrecioDia = new javax.swing.JLabel();
        precioDia = new javax.swing.JTextField();
        lblPorcentCancel = new javax.swing.JLabel();
        porcentCancel = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        listaCfAula = new javax.swing.JList();
        jPanel1 = new javax.swing.JPanel();
        lblIdAula = new javax.swing.JLabel();
        nombre = new javax.swing.JTextField();
        lblAforo = new javax.swing.JLabel();
        aforo = new javax.swing.JTextField();
        lblSuperficie = new javax.swing.JLabel();
        superficie = new javax.swing.JTextField();
        lblDescripcion = new javax.swing.JLabel();
        descripcion = new javax.swing.JTextField();
        lblNombre = new javax.swing.JLabel();
        idAula = new javax.swing.JTextField();
        inactiva = new javax.swing.JCheckBox();
        jPanel2 = new javax.swing.JPanel();
        lblCiudad = new javax.swing.JLabel();
        lblDireccion = new javax.swing.JLabel();
        direccion = new javax.swing.JTextField();
        lblCoordGps = new javax.swing.JLabel();
        gpsX = new javax.swing.JTextField();
        gpsY = new javax.swing.JTextField();
        lblComoLlegar = new javax.swing.JLabel();
        comoLlegar = new javax.swing.JTextField();
        ciudad = new javax.swing.JTextField();
        nomCiudad = new javax.swing.JTextField();
        btnBuscar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        btnModificacion.setText(TDSLanguageUtils.getMessage("mantenimiento.gui.boton.modificacion"));
        btnModificacion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnModificacionActionPerformed(evt);
            }
        });

        btnVolver.setText(TDSLanguageUtils.getMessage("mantenimiento.gui.boton.volver"));
        btnVolver.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVolverActionPerformed(evt);
            }
        });

        btnBaja.setText(TDSLanguageUtils.getMessage("mantenimiento.gui.boton.activar"));
        btnBaja.setEnabled(false);
        btnBaja.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBajaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelBotonesLayout = new javax.swing.GroupLayout(panelBotones);
        panelBotones.setLayout(panelBotonesLayout);
        panelBotonesLayout.setHorizontalGroup(
            panelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelBotonesLayout.createSequentialGroup()
                .addGap(17, 17, 17)
                .addComponent(btnBaja)
                .addGap(18, 18, 18)
                .addComponent(btnModificacion)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 107, Short.MAX_VALUE)
                .addComponent(btnVolver)
                .addGap(18, 18, 18))
        );
        panelBotonesLayout.setVerticalGroup(
            panelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelBotonesLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(panelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnModificacion)
                    .addComponent(btnBaja, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnVolver))
                .addContainerGap())
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, TDSLanguageUtils.getMessage("mantenimiento.gui.panel.precio"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        lblPrecioHora.setText(TDSLanguageUtils.getMessage("mantenimiento.gui.etiqueta.preciohora"));

        precioHora.setFont(new java.awt.Font("Tahoma", 1, 11));
        precioHora.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        lblPrecioDia.setText(TDSLanguageUtils.getMessage("mantenimiento.gui.etiqueta.preciodia"));

        precioDia.setFont(new java.awt.Font("Tahoma", 1, 11));
        precioDia.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        lblPorcentCancel.setText(TDSLanguageUtils.getMessage("mantenimiento.gui.etiqueta.porctcancel"));

        porcentCancel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        porcentCancel.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(lblPorcentCancel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(porcentCancel, javax.swing.GroupLayout.DEFAULT_SIZE, 77, Short.MAX_VALUE))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblPrecioDia)
                            .addComponent(lblPrecioHora))
                        .addGap(12, 12, 12)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(precioDia, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(precioHora, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 62, Short.MAX_VALUE))))
                .addGap(10, 10, 10))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(precioHora, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblPrecioHora))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(precioDia, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblPrecioDia))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 54, Short.MAX_VALUE)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblPorcentCancel)
                    .addComponent(porcentCancel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, TDSLanguageUtils.getMessage("mantenimiento.gui.panel.cfisicas"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        jScrollPane1.setViewportView(listaCfAula);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 231, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE)
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, TDSLanguageUtils.getMessage("mantenimiento.gui.panel.aula"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        lblIdAula.setText(TDSLanguageUtils.getMessage("mantenimiento.gui.etiqueta.idaula"));

        nombre.setFont(new java.awt.Font("Tahoma", 1, 11));

        lblAforo.setText(TDSLanguageUtils.getMessage("mantenimiento.gui.etiqueta.aforo"));

        aforo.setFont(new java.awt.Font("Tahoma", 1, 11));
        aforo.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        lblSuperficie.setText(TDSLanguageUtils.getMessage("mantenimiento.gui.etiqueta.superficie"));

        superficie.setFont(new java.awt.Font("Tahoma", 1, 11));
        superficie.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        lblDescripcion.setText(TDSLanguageUtils.getMessage("mantenimiento.gui.etiqueta.descripcion"));

        lblNombre.setText(TDSLanguageUtils.getMessage("mantenimiento.gui.etiqueta.nombre"));

        idAula.setEditable(false);
        idAula.setFont(new java.awt.Font("Tahoma", 1, 11));
        idAula.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        inactiva.setText(TDSLanguageUtils.getMessage("mantenimiento.gui.etiqueta.inactiva"));
        inactiva.setEnabled(false);
        inactiva.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                inactivaItemStateChanged(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(lblIdAula)
                        .addGap(18, 18, 18)
                        .addComponent(idAula, javax.swing.GroupLayout.DEFAULT_SIZE, 409, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(lblSuperficie)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(superficie, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblAforo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(aforo, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(inactiva))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblDescripcion)
                            .addComponent(lblNombre))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(descripcion, javax.swing.GroupLayout.DEFAULT_SIZE, 423, Short.MAX_VALUE)
                            .addComponent(nombre, javax.swing.GroupLayout.DEFAULT_SIZE, 423, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblIdAula)
                    .addComponent(idAula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblNombre)
                    .addComponent(nombre, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblDescripcion)
                    .addComponent(descripcion, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(superficie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblSuperficie)
                        .addComponent(lblAforo)
                        .addComponent(aforo, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(inactiva))
                .addGap(28, 28, 28))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, TDSLanguageUtils.getMessage("mantenimiento.gui.panel.direccion"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        lblCiudad.setText(TDSLanguageUtils.getMessage("mantenimiento.gui.etiqueta.localidad"));

        lblDireccion.setText(TDSLanguageUtils.getMessage("mantenimiento.gui.etiqueta.direccion"));

        direccion.setFont(new java.awt.Font("Tahoma", 1, 11));
        direccion.setHorizontalAlignment(javax.swing.JTextField.LEFT);

        lblCoordGps.setText(TDSLanguageUtils.getMessage("mantenimiento.gui.etiqueta.gps"));

        gpsX.setFont(new java.awt.Font("Tahoma", 1, 11));
        gpsX.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        gpsY.setFont(new java.awt.Font("Tahoma", 1, 11));
        gpsY.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        lblComoLlegar.setText(TDSLanguageUtils.getMessage("mantenimiento.gui.etiqueta.comollegar"));

        comoLlegar.setFont(new java.awt.Font("Tahoma", 1, 11));
        comoLlegar.setHorizontalAlignment(javax.swing.JTextField.LEFT);

        ciudad.setEditable(false);

        nomCiudad.setEditable(false);

        btnBuscar.setText(TDSLanguageUtils.getMessage("mantenimiento.gui.boton.buscar"));
        btnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(lblDireccion)
                        .addGap(19, 19, 19)
                        .addComponent(direccion, javax.swing.GroupLayout.DEFAULT_SIZE, 408, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(lblComoLlegar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(comoLlegar, javax.swing.GroupLayout.DEFAULT_SIZE, 423, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(lblCiudad)
                        .addGap(18, 18, 18)
                        .addComponent(ciudad, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(nomCiudad, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE)
                        .addComponent(btnBuscar))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(lblCoordGps)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(gpsX, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(gpsY, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(direccion, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblDireccion))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblCiudad)
                    .addComponent(ciudad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnBuscar)
                    .addComponent(nomCiudad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblCoordGps)
                    .addComponent(gpsX, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(gpsY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblComoLlegar)
                    .addComponent(comoLlegar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(48, 48, 48))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(panelBotones, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(21, 21, 21)
                .addComponent(panelBotones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnVolverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVolverActionPerformed
        dispose();
    }//GEN-LAST:event_btnVolverActionPerformed

    private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarActionPerformed
        Frame frame = JOptionPane.getFrameForComponent(this);
        DialogLocalidad dlgLocalidad = new DialogLocalidad(frame, true, usLogeado);
        dlgLocalidad.setVisible(true);
        CiudadDTO ciudadBuscada = dlgLocalidad.getCiudad();
        ciudad.setText(String.valueOf(ciudadBuscada.getIdCiudad()));
        nomCiudad.setText(ciudadBuscada.getNomCiudad());
    }//GEN-LAST:event_btnBuscarActionPerformed

    private void btnBajaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBajaActionPerformed
        AuditoriaDTO auditoria = new AuditoriaDTO();
        try {

            if (inactiva.isSelected()) {
                // Damos de baja lógica al aula
                objRemotoMantenimiento.bajaAula(Integer.parseInt(idAula.getText()));

                JOptionPane.showMessageDialog(null, TDSLanguageUtils.getMessage("mantenimiento.aula.baja.correcta"));

                auditaModificacion(Constantes.BAJA);

            } else {
                // Reactivamos el aula
                objRemotoMantenimiento.activaAula(Integer.parseInt(idAula.getText()));

                JOptionPane.showMessageDialog(null, TDSLanguageUtils.getMessage("mantenimiento.aula.altalogica.correcta"));

                auditaModificacion(Constantes.ALTA);
            }
            dispose();

        } catch (RemoteException eRe) {
            JOptionPane.showMessageDialog(null,
                    eRe.getMessage(), TDSLanguageUtils.getMessage("gmantenimiento.err.aula.baja"),
                    JOptionPane.ERROR_MESSAGE);
        } catch (GestorMantenimientoException gmE) {
            JOptionPane.showMessageDialog(null,
                    gmE.getMessage(), TDSLanguageUtils.getMessage("gmantenimiento.err.aula.baja"),
                    JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_btnBajaActionPerformed

    private void inactivaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_inactivaItemStateChanged

        btnBaja.setEnabled(true);
        btnModificacion.setEnabled(false);

    }//GEN-LAST:event_inactivaItemStateChanged

    private void btnModificacionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnModificacionActionPerformed
        // Comprobación de los precios introducidos
        if (!ValidarGUI.isDouble(precioDia.getText())) {
            JOptionPane.showMessageDialog(null, TDSLanguageUtils.getMessage("mantenimiento.gui.err.decimal"));
            precioDia.setText("");
            return;
        }

        if (!ValidarGUI.isDouble(precioHora.getText())) {
            JOptionPane.showMessageDialog(null, TDSLanguageUtils.getMessage("mantenimiento.gui.err.decimal"));
            precioHora.setText("");
            return;
        }

        try {
            AuditoriaDTO auditoria = new AuditoriaDTO();
            AulaDTO aula = new AulaDTO();

            aula.setIdAula(Integer.parseInt(idAula.getText().trim()));
            aula.setNomAula(nombre.getText());
            aula.setDescripcion(descripcion.getText());
            aula.setDireccion(direccion.getText());
            aula.setIdCiudad(Integer.parseInt(ciudad.getText()));
            aula.setNomCiudad(nomCiudad.getText());
            aula.setSuperficie(Double.parseDouble(superficie.getText()));
            aula.setAforo(Integer.parseInt(aforo.getText()));
            aula.setPrecioHora(Double.parseDouble(precioHora.getText()));
            aula.setPrecioDia(Double.parseDouble(precioDia.getText()));
            aula.setPorcentCancelacion(Double.parseDouble(porcentCancel.getText()));
            aula.setCoordGpsX(Double.parseDouble(gpsX.getText()));
            aula.setCoordGpsY(Double.parseDouble(gpsY.getText()));
            aula.setPlano(comoLlegar.getText());

            if (inactiva.isSelected()) {
                aula.setInactivo(Constantes.INACTIVO);
            } else {
                aula.setInactivo(Constantes.ACTIVO);
            }

            objRemotoMantenimiento.modificaAula(aula);

            JOptionPane.showMessageDialog(null, TDSLanguageUtils.getMessage("mantenimiento.aula.modificacion.correcta"));

            auditaModificacion(Constantes.MODIFICACION);

            dispose();

        } catch (GestorMantenimientoException gmE) {
            JOptionPane.showMessageDialog(null,
                    gmE.getMessage(), TDSLanguageUtils.getMessage("gmantenimiento.err.aula.modificacion"),
                    JOptionPane.ERROR_MESSAGE);
        } catch (RemoteException rE) {
            JOptionPane.showMessageDialog(null,
                    rE.getMessage(), TDSLanguageUtils.getMessage("gmantenimiento.err.aula.modificacion"),
                    JOptionPane.ERROR_MESSAGE);
        }

    }//GEN-LAST:event_btnModificacionActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField aforo;
    private javax.swing.JButton btnBaja;
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton btnModificacion;
    private javax.swing.JButton btnVolver;
    private javax.swing.JTextField ciudad;
    private javax.swing.JTextField comoLlegar;
    private javax.swing.JTextField descripcion;
    private javax.swing.JTextField direccion;
    private javax.swing.JTextField gpsX;
    private javax.swing.JTextField gpsY;
    private javax.swing.JTextField idAula;
    private javax.swing.JCheckBox inactiva;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblAforo;
    private javax.swing.JLabel lblCiudad;
    private javax.swing.JLabel lblComoLlegar;
    private javax.swing.JLabel lblCoordGps;
    private javax.swing.JLabel lblDescripcion;
    private javax.swing.JLabel lblDireccion;
    private javax.swing.JLabel lblIdAula;
    private javax.swing.JLabel lblNombre;
    private javax.swing.JLabel lblPorcentCancel;
    private javax.swing.JLabel lblPrecioDia;
    private javax.swing.JLabel lblPrecioHora;
    private javax.swing.JLabel lblSuperficie;
    private javax.swing.JList listaCfAula;
    private javax.swing.JTextField nomCiudad;
    private javax.swing.JTextField nombre;
    private javax.swing.JPanel panelBotones;
    private javax.swing.JTextField porcentCancel;
    private javax.swing.JTextField precioDia;
    private javax.swing.JTextField precioHora;
    private javax.swing.JTextField superficie;
    // End of variables declaration//GEN-END:variables

    private void rellenaDatos(AulaDTO aula) throws RemoteException, GestorMantenimientoException {

        if (aula == null) {
            JOptionPane.showMessageDialog(null, TDSLanguageUtils.getMessage("mantenimiento.aula.err.buscar"));
            dispose();
        } else {
            try {
                //Obtenemos los datos del aula
                idAula.setText(String.valueOf(aula.getIdAula()));
                nombre.setText(aula.getNomAula());
                descripcion.setText(aula.getDescripcion());
                direccion.setText(aula.getDireccion());
                ciudad.setText(String.valueOf(aula.getIdCiudad()));
                nomCiudad.setText(aula.getNomCiudad());
                superficie.setText(UtilidadesGUI.obtenerDecimal(aula.getSuperficie()));
                aforo.setText(String.valueOf(aula.getAforo()));
                precioHora.setText(UtilidadesGUI.obtenerDecimal(aula.getPrecioHora()));
                precioDia.setText(UtilidadesGUI.obtenerDecimal(aula.getPrecioDia()));
                porcentCancel.setText(UtilidadesGUI.obtenerDecimal(aula.getPorcentCancelacion()));
                gpsX.setText(String.valueOf(aula.getCoordGpsX()));
                gpsY.setText(String.valueOf(aula.getCoordGpsY()));
                comoLlegar.setText(aula.getPlano());

                if (aula.getInactivo() == Constantes.INACTIVO) {
                    inactiva.setSelected(true);
                    inactiva.setEnabled(true);
                } else if (aula.getInactivo() == Constantes.ACTIVO) {
                    inactiva.setEnabled(true);
                    inactiva.setSelected(false);
                }
                //Obtenemos la lista de características físicas del aula
                List<CFisicaDTO> cfAula = objRemotoMantenimiento.cFisicasFromAula(aula.getIdAula());
                
                itemAula = new DefaultListModel();
                listaCfAula.setModel(itemAula);

                for (int i = 0; i < cfAula.size(); i++) {
                    itemAula.addElement(cfAula.get(i));
                }
                listaCfAula.setModel(itemAula);

            } catch (RemoteException eRe) {
                JOptionPane.showMessageDialog(null,
                        eRe.getMessage(), TDSLanguageUtils.getMessage("mantenimiento.aula.alta.err.listas"),
                        JOptionPane.ERROR_MESSAGE);
            } catch (GestorMantenimientoException ex) {
                JOptionPane.showMessageDialog(null,
                        ex.getMessage(), TDSLanguageUtils.getMessage("mantenimiento.aula.alta.err.listas"),
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    }

    /**
     * Realiza la auditoría de movimientos de modificación de datos de
     * equipamiento
     */
    private void auditaModificacion(String operacion) {

        AuditoriaDTO auditoria = new AuditoriaDTO();

        try {
            auditoria.setObjeto(Constantes.AULA);
            auditoria.setSujeto(idConectado);
            auditoria.setPk(idAula.getText());
            auditoria.setOperacion(operacion);

            objRemotoMantenimiento.altaAuditoria(auditoria);
        } catch (GestorMantenimientoException gmE) {
            JOptionPane.showMessageDialog(null,
                    gmE.getMessage(), TDSLanguageUtils.getMessage("auditoria.aula.err.modificacion"),
                    JOptionPane.ERROR_MESSAGE);
        } catch (RemoteException rE) {
            JOptionPane.showMessageDialog(null,
                    rE.getMessage(), TDSLanguageUtils.getMessage("auditoria.aula.err.modificacion"),
                    JOptionPane.ERROR_MESSAGE);
        }
    }

    private void inicializarComponentes() {
        btnBaja.setEnabled(false);
        btnModificacion.setEnabled(true);
    }
}
